package com.itheima.controller;

import cn.hutool.core.bean.BeanUtil;
import com.itheima.common.R;
import com.itheima.pojo.Category;
import com.itheima.service.CategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author 小帅蓝
 * @Date 2022/6/23 15:26
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/list")
    public R<List<Category>> getList() {
        List<Category> list = categoryService.categoryList(null);
        List<Category> vos = new ArrayList<>();
        for (Category category : list) {
            Category vo = new Category();
            BeanUtil.copyProperties(category, vo);
            vos.add(vo);
        }
        return R.success(vos);
    }

}
